<?

//$img_src=imagecreatefromjpeg("http://data.wetter.info//data/maps/basemaps/xxlradar-de.jpg");

//$img_src=imagecreatefromgif("http://data.wetter.info//data/layers/xxlradar-de/xxlradar-de_radar_" . $_GET["id"]);
//$im=imagecreatetruecolor("700","500");
//
////preserve alpha
//imagecolortransparent($im, imagecolorallocate($im, 0, 0, 0));
//imagealphablending($im, false);
//imagesavealpha($im, true);
//imagecopymerge($im, $img_src, 0, 0, 0, 150, "932", "1049", "100");

  $image = file_get_contents("http://data.wetter.info//data/layers/xxlradar-de/xxlradar-de_radar_" . $_GET["id"]);
   $name = "/tmp/" .  $_GET["id"]);
   file_put_contents($name, $image);
$picture = new Imagick($name);

$picture->cropImage(700, 500, 0, 150);
    $picture->setImagePage(0, 0, 0, 0); // Remove canvas

                $UTCdatum = substr($_GET["id"],0,12);

    $dateSrc = substr($UTCdatum,0,4)."-". substr($UTCdatum,4,2) . "-" . substr($UTCdatum,6,2)." ".substr($UTCdatum,8,2).":".substr($UTCdatum,10,2)." GMT"; 
    $dateTime = new DateTime($dateSrc); 
    



$tekst = date('H:i:s', strtotime($dateSrc));
$draw = new ImagickDraw();

/* Black text */
$draw->setFillColor('black');

/* Font properties */
$draw->setFont('images/arial.ttf');
$draw->setFontSize( 18 );

/* Create text */
$picture->annotateImage($draw, 16, 31, 0,$tekst);
$draw->setFillColor('white');
$picture->annotateImage($draw, 15, 30, 0,$tekst);

//$napis = imagecolorallocate($im, 240, 240, 240);
//imagettftext($im,16, 0, 570, 30, $napis, "images/arial.ttf", $tekst);




//final output
header('Content-type: image/gif');
echo $picture;
//imagegif($im);

?>